package ssn.common.view;

import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.view.AbstractView;

import ssn.common.vo.FileVO;

@SuppressWarnings("rawtypes")
public class AjaxFileView extends AbstractView {

	@Override
	protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
	        throws Exception {
		PrintWriter writer = null;
		try{
			response.setContentType("text/html; charset=UTF-8");
			response.setHeader("Cache-Control", "no-cache");
			FileVO fileVO = (FileVO)model.get("fileVO");
			
			StringBuffer bf = new StringBuffer();
			if(fileVO != null){
				bf.append("{");
				bf.append("\"status\":\"success\",");
				bf.append("\"orgFN\":\""+fileVO.getOriFileName()+"\",");
				bf.append("\"saveFN\":\""+fileVO.getSaveFileName()+fileVO.getFileExt()+"\",");
				bf.append("\"fileSize\":\""+fileVO.getFileSize()+"\",");
				bf.append("\"tmpUrl\":\""+fileVO.getTempFullUrl()+"\"");
				bf.append("}");
			}else{
				bf.append("{");
				bf.append("\"status\":\"error\",");
				bf.append("\"orgFN\":\"\",");
				bf.append("\"saveFN\":\"\",");
				bf.append("\"fileSize\":\"\",");
				bf.append("\"tmpPath\":\"\"");
				bf.append("}");
			}
			writer = response.getWriter();
			writer.write(bf.toString());
		} finally {
			writer.close();
		}
	}
}